<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>功能模块管理</title>
  <link rel="stylesheet" href="${ctx}/static/admin/layui/css/layui.css">
	<link rel="stylesheet" href="${ctx}/static/admin/css/formSelects-v4.css">
  <link rel="stylesheet" href="${ctx}/static/admin/css/sidebar.css">
  <link rel="stylesheet" href="${ctx}/static/admin/css/switch.css">
</head>
  <body>
	<div class="layui-card-body">
		<!--<#button permission="modulesbtnadd" id="add" size="layui-btn-sm" textName="附件上传" event="add"/>-->
		<#button permission="" id="add" size="layui-btn-sm" textName="附件上传" event="add"/>
		<!-- <button id="add" class="layui-btn layui-btn-sm">新增</button> -->
		<!-- <button id="export" class="layui-btn layui-btn-sm">导出</button> -->
		<table id="modulestable" lay-filter="modules"></table>
	</div>
  </body>
</html>
<script src="${ctx}/static/admin/layui/layui.js"></script>
<script src="${ctx}/static/admin/js/common.js"></script>
<script type="text/html" id="toolbar">
<#button permission="" iconCls="layui-btn" size="layui-btn-xs" textName="预览" event="preview"/>
<#button permission="" iconCls="layui-btn-normal" size="layui-btn-xs" textName="下载" event="download"/>
<#button permission="" iconCls="layui-btn-danger" size="layui-btn-xs" textName="删除" event="del"/>
{{#
if(d.createuser == ${session.sysUser.id}){
}}
<#button permission="modulesbtndel" iconCls="layui-btn-danger" size="layui-btn-xs" textName="删除" event="del"/>
{{#
}
}}
</script>
<script type="text/javascript">
var tableIns;
var $;
layui.use(['table','layer','jquery','element','sidebar','form','formSelects'], function(){
	$ = jQuery = layui.$;
	var table = layui.table;
	var layer = layui.layer;
	var element = layui.element;
	var sidebar = layui.sidebar;
    var form = layui.form;
    var formSelects = layui.formSelects;

	tableIns = table.render({
		elem: '#modulestable',
		height:'full-113',
		size:'sm',
	    url: '${ctx}/sys_admin/mineservice/getAttachList',
		where: {'tablename': '${tablename!}', 'parentid':'${parentid!}'},
	    even: true,
	    cols: [[
	        {type: 'numbers',fixed: 'left'},
            {field: 'id', title: 'ID',fixed: 'left', align:'center',width:100, hide:true},
            {field: 'name', title: '附件名称',fixed: 'left', align:'center',width:300},
            {field: 'realname', title: '附件实际名称', align:'center'},
            {title: '操作', width: 280, fixed: 'right', align:'center',toolbar: '#toolbar'}
        ]]
	});
	table.on('tool(modules)', function(obj){
	    var data = obj.data;
	    if(obj.event === 'del'){
	    	layer.confirm('确定删除行么？', function(index){
	    	  $.post('${ctx}/sys_admin/mineservice/deleteFile', {"tablename":"${tablename!}", "ids":data.id}, function(result) {
	  			if (result.success) {
                    layer.open({
                        skin:'layui-layer-success',
                        title:'提示',
                        content:'删除成功！',
                        yes:function(idx, layero){
                            tableIns.reload({});
                            layer.close(index);
                            layer.close(idx);
                        }
                    });
	  				//obj.del();
	  			} else {
	  				layer.msg(result.msg);
	  			}
	  		  }, 'json');
	      });
	    }else if(obj.event === 'download'){
            downFileByIframe("${ctx}/sys_admin/mineservice/fileDownload?id="+data.id+"&tablename=${tablename!}");
        }else if(obj.event === 'preview'){
            var fileUrl = "${ctx}/upload/${tablename!}/"+data.realname;
            var url = "http://116.63.43.8:8012/onlinePreview?url=" + encodeURIComponent(fileUrl);
            var winHeight = window.document.documentElement.clientHeight-10;
            window.open(url, "_blank", "height=" + winHeight + ", top=30, left=40, toolbar=no, menubar=no, scrollbars=yes, resizable=yes ");
        }
	});

	$("#add").on('click',function(){
		parent.layer.open({
			type: 2,
			area: ['90%', '90%'],
			fixed: false, //不固定
			maxmin: true,
			content: '${ctx}/sys_admin/mineservice/uploadForm?tablename=${tablename!}&parentid=${parentid!}',
            btn: ['关闭'],
            yes: function(index, layero){
                tableIns.reload({});
                parent.layer.close(index); //再执行关闭
            }
		});
	});
	
	form.on('submit(serach_form)', function (data) {
         table.reload('modulestable', {
             method : 'post',
             where: data.field,
             page: {
			     curr : 1 //重新从第 1 页开始
			 }
         });
         params = data.field;
         return false;
     });
	
	$("#export").on('click',function(){
		window.open('${ctx}/modules/exportExcel');
	})
	
});

</script>